package org.apache.dolphinscheduler.api.service.impl;

import org.apache.dolphinscheduler.api.page.PageQuery;
import org.apache.dolphinscheduler.api.page.TableDataInfo;
import org.apache.dolphinscheduler.api.service.NetworkService;
import org.apache.dolphinscheduler.dao.entity.Network;
import org.apache.dolphinscheduler.dao.mapper.NetworkMapper;

import org.apache.commons.lang3.StringUtils;

import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

/**
 * <p>
 * 虚拟网络表 服务实现类
 * </p>
 *
 * @author denggh
 * @since 2023-02-08
 */
@Service
public class NetworkServiceImpl extends ServiceImpl<NetworkMapper, Network> implements NetworkService {

    @Override
    public TableDataInfo<Network> selectPageNetworkList(Network network, PageQuery pageQuery) {
        LambdaQueryWrapper<Network> lqw = new LambdaQueryWrapper<Network>();
        if (StringUtils.isNotBlank(network.getName())) {
            lqw.like(Network::getName, network.getName());
        }
        IPage<Network> page = baseMapper.selectPage(pageQuery.build(), lqw);
        return TableDataInfo.build(page);
    }

    @Override
    public Network selectNetworkById(Long networkId) {
        return baseMapper.selectById(networkId);
    }

    @Override
    public int insertNetwork(Network network) {
        return baseMapper.insert(network);
    }

    @Override
    public int updateNetwork(Network network) {
        return baseMapper.updateById(network);
    }

    @Override
    public int deleteNetworkById(Long networkId) {
        return baseMapper.deleteById(networkId);
    }
}
